package com.pocketsweet.chatlib.utils;

import java.io.File;
import java.io.IOException;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;

import com.pocketsweet.MLApplication;
import com.pocketsweet.service.UserService;
import com.pocketsweet.utils.PhotoUtil;
import com.squareup.picasso.Transformation;

public class PicassoSquare implements Transformation {
	private String imagename;
	private String username;

	public PicassoSquare() {
		super();
	}

	public PicassoSquare(String username, String imagename) {
		super();
		this.imagename = imagename.split("/")[imagename.split("/").length - 1];
		this.username = username;
	}

	@SuppressLint("SdCardPath")
	@Override
	public Bitmap transform(Bitmap source) {
		int size = Math.min(source.getWidth(), source.getHeight());
		Bitmap result = PhotoUtil.toRoundCorner(source, source.getWidth() / 12);
//		File[] files = new File(MLApplication.getContext().getFilesDir() + "/"
//				+username +"/").listFiles();
//		File file = null;
//		if(files!=null&&files.length!=0){
//			file = files[0];
//		}
//		if(file!=null)
//			file.delete();
//		PhotoUtil.saveBitmap(MLApplication.getContext().getFilesDir() + "/"
//				+ username + "/", imagename, result, true);
		if (result != source) {
			source.recycle();
		}
		return result;
	}

	@Override
	public String key() {
		return "square()";
	}
}
